package com.logic.landseaserver.models.rental.ws;

import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logic.common.enums.HttpCodeEnum;
import com.logic.landseaserver.common.exception.LandseaException;
import com.logic.landseaserver.common.exception.ResultCodes.RentalResultCode;
import com.logic.landseaserver.models.rental.bean.PrjRoomDataReq;
import com.logic.landseaserver.models.rental.bean.UploadOrderInfoReq;
import com.logic.landseaserver.models.rental.common.ResponsResult;
import com.logic.landseaserver.models.rental.service.RentalService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Path("/rental")
@Api(value = "朗诗租房平台房源信息获取")
public class RentalRest
{
    private static final Logger logger = LoggerFactory.getLogger(RentalRest.class);
    
    @Autowired
    private RentalService rentalService;
    
    @POST
    @Path("/syncPrjRoomData")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "集中式房源信息获取")
    public Response syncPrjRoomData(
    		@ApiParam(value = "param", required = true) PrjRoomDataReq req)
    {
    	ResponsResult responsResult = null;
        try
        {
        	if (rentalService.verifyData(req)) 
        	{
        		Map<String, List<Map<String, Object>>> resp = rentalService.syncPrjRoomData(req);
            	responsResult = ResponsResult.success(resp);
			}
        	else
        	{
        		logger.error("秘钥无效.");
    			throw LandseaException.createException(RentalResultCode.E011510010);
        	}
        	
        }
        catch (LandseaException e)
        {
        	logger.error("集中式房源信息获取" + e.getMessage());
            responsResult = ResponsResult.exception(e.getResultCode());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(responsResult).build();
    }
    
    @POST
    @Path("/uploadOrderInfo")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "预约信息上报")
    public Response uploadOrderInfo(
    		@ApiParam(value = "param", required = true) UploadOrderInfoReq req)
    {
    	ResponsResult responsResult = null;
        try
        {
        	if (rentalService.verifyUpload(req)) 
        	{
        		rentalService.uploadOrderInfo(req);
            	responsResult = ResponsResult.success();
			}
        	else
        	{
        		logger.error("秘钥无效.");
    			throw LandseaException.createException(RentalResultCode.E011510010);
        	}
        	
        }
        catch (LandseaException e)
        {
        	logger.error("预约信息上报" + e.getMessage());
            responsResult = ResponsResult.exception(e.getResultCode());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(responsResult).build();
    }
    
}
